/*
 * Copyright 2016 Toradex AG
 *
 * This file is dual-licensed: you can use it either under the terms
 * of the GPL or the X11 license, at your option. Note that this dual
 * licensing only applies to this file, and not this project as a
 * whole.
 *
 *  a) This file is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License
 *     version 2 as published by the Free Software Foundation.
 *
 *     This file is distributed in the hope that it will be useful
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 * Or, alternatively
 *
 *  b) Permission is hereby granted, free of charge, to any person
 *     obtaining a copy of this software and associated documentation
 *     files (the "Software"), to deal in the Software without
 *     restriction, including without limitation the rights to use
 *     copy, modify, merge, publish, distribute, sublicense, and/or
 *     sell copies of the Software, and to permit persons to whom the
 *     Software is furnished to do so, subject to the following
 *     conditions:
 *
 *     The above copyright notice and this permission notice shall be
 *     included in all copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
 *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
 *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *     OTHER DEALINGS IN THE SOFTWARE.
 */

/dts-v1/;

#include <dt-bindings/input/input.h>
#include "tegra124-apalis.dtsi"

/ {
	model = "Toradex Apalis TK1 on Apalis Evaluation Board";
	compatible = "toradex,apalis-tk1-eval", "toradex,apalis-tk1",
		     "nvidia,tegra124";

	aliases {
		rtc0 = "/i2c@7000c000/rtc@68";
		rtc1 = "/i2c@7000d000/pmic@40";
		rtc2 = "/rtc@7000e000";
		serial0 = &uarta;
		serial1 = &uartb;
		serial2 = &uartc;
		serial3 = &uartd;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	pcie-controller@01003000 {
		pci@1,0 {
			status = "okay";
		};
	};

	host1x@50000000 {
		hdmi@54280000 {
			status = "okay";
		};
	};

	/* Apalis UART1 */
	serial@70006000 {
		status = "okay";
	};

	/* Apalis UART2 */
	serial@70006040 {
		status = "okay";
	};

	/* Apalis UART3 */
	serial@70006200 {
		status = "okay";
	};

	/* Apalis UART4 */
	serial@70006300 {
		status = "okay";
	};

	pwm@7000a000 {
		status = "okay";
	};

	/*
	 * GEN1_I2C: I2C1_SDA/SCL on MXM3 pin 209/211 (e.g. RTC on carrier
	 * board)
	 */
	i2c@7000c000 {
		status = "okay";
		clock-frequency = <100000>;

		pcie-switch@58 {
			compatible = "plx,pex8605";
			reg = <0x58>;
		};

		/* M41T0M6 real time clock on carrier board */
		rtc@68 {
			compatible = "st,m41t00";
			reg = <0x68>;
		};
	};

	/*
	 * GEN2_I2C: I2C2_SDA/SCL (DDC) on MXM3 pin 205/207 (e.g. display EDID)
	 */
	hdmi_ddc: i2c@7000c400 {
		status = "okay";
		clock-frequency = <100000>;
	};

	/*
	 * CAM_I2C: I2C3_SDA/SCL (CAM) on MXM3 pin 201/203 (e.g. camera sensor
	 * on carrier board)
	 */
	i2c@7000c500 {
		status = "okay";
		clock-frequency = <100000>;
	};

	/* I2C4 (DDC): unused */

	/* SPI1: Apalis SPI1 */
	spi@7000d400 {
		status = "okay";
		spi-max-frequency = <50000000>;

		spidev0: spidev@0 {
			compatible = "spidev";
			reg = <0>;
			spi-max-frequency = <50000000>;
		};
	};

	/* SPI4: Apalis SPI2 */
	spi@7000da00 {
		status = "okay";
		spi-max-frequency = <50000000>;

		spidev1: spidev@0 {
			compatible = "spidev";
			reg = <0>;
			spi-max-frequency = <50000000>;
		};
	};

	/* Apalis Serial ATA */
	sata@70020000 {
		status = "okay";
	};

	hda@70030000 {
		status = "okay";
	};

	usb@70090000 {
		status = "okay";
	};

	/* Apalis MMC1 */
	sdhci@700b0000 {
		status = "okay";
		/* MMC1_CD# */
		cd-gpios = <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_LOW>;
		bus-width = <4>;
		vqmmc-supply = <&vddio_sdmmc1>;
	};

	/* Apalis SD1 */
	sdhci@700b0400 {
		status = "okay";
		/*
		 * Don't use SD1_CD# aka SDMMC3_CLK_LB_OUT for now as it
		 * features some magic properties even though the external
		 * loopback is disabled and the internal loopback used as per
		 * SDMMC_VENDOR_MISC_CNTRL_0 register's SDMMC_SPARE1 bits being
		 * set to 0xfffd according to the TRM!
		 * cd-gpios = <&gpio TEGRA_GPIO(EE, 4) GPIO_ACTIVE_LOW>;
		 */
		bus-width = <4>;
		vqmmc-supply = <&vddio_sdmmc3>;
	};

	/* EHCI instance 0: USB1_DP/N -> USBO1_DP/N */
	usb@7d000000 {
		status = "okay";
		dr_mode = "otg";
	};

	usb-phy@7d000000 {
		status = "okay";
		vbus-supply = <&reg_usbo1_vbus>;
	};

	/* EHCI instance 1: USB2_DP/N -> USBH2_DP/N */
	usb@7d004000 {
		status = "okay";
	};

	usb-phy@7d004000 {
		status = "okay";
		vbus-supply = <&reg_usbh_vbus>;
	};

	/* EHCI instance 2: USB3_DP/N -> USBH4_DP/N */
	usb@7d008000 {
		status = "okay";
	};

	usb-phy@7d008000 {
		status = "okay";
		vbus-supply = <&reg_usbh_vbus>;
	};

	backlight: backlight {
		compatible = "pwm-backlight";

		/* BKL1_PWM */
		pwms = <&pwm 3 5000000>;
		brightness-levels = <255 231 223 207 191 159 127 0>;
		default-brightness-level = <6>;
		/* BKL1_ON */
		enable-gpios = <&gpio TEGRA_GPIO(BB, 5) GPIO_ACTIVE_HIGH>;
	};

	gpio-keys {
		compatible = "gpio-keys";

		wakeup {
			label = "WAKE1_MICO";
			gpios = <&gpio TEGRA_GPIO(DD, 3) GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WAKEUP>;
			debounce-interval = <10>;
			wakeup-source;
		};
	};

	reg_5v0: regulator-5v0 {
		compatible = "regulator-fixed";
		regulator-name = "5V_SW";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
	};

	/* USBO1_EN */
	reg_usbo1_vbus: regulator-usbo1-vbus {
		compatible = "regulator-fixed";
		regulator-name = "VCC_USBO1";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio TEGRA_GPIO(N, 4) GPIO_ACTIVE_HIGH>;
		enable-active-high;
		vin-supply = <&reg_5v0>;
	};

	/* USBH_EN */
	reg_usbh_vbus: regulator-usbh-vbus {
		compatible = "regulator-fixed";
		regulator-name = "VCC_USBH(2A|2C|2D|3|4)";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio TEGRA_GPIO(N, 5) GPIO_ACTIVE_HIGH>;
		enable-active-high;
		vin-supply = <&reg_5v0>;
	};
};
